<template>
  <div class="refresh-container" @click="handleRefresh">
    <div class="refresh-button" :class="{ 'rotating': isRotating }">
      <span class="refresh-icon">🪙</span>
      <div class="particle-effect"></div>
      <div class="glow-ring"></div>
    </div>
    <span class="refresh-text" v-if="!isRotating">刷新</span>
    <span class="loading-text" v-if="isRotating">加载中...</span>
  </div>
</template>

<script>
export default {
  name: 'RefreshButton',
  data()
  {
    return {
      isRotating: false
    }
  },
  methods: {
    async handleRefresh()
    {
      if (this.isRotating) return // 防止重复点击

      this.isRotating = true
      try
      {
        // 模拟异步刷新操作（2秒后完成）
        await new Promise(resolve => setTimeout(resolve, 2000))
      }
      catch (error)
      {
        console.error('刷新失败:', error)
      }
      finally
      {
        this.isRotating = false
      }
    }
  }
}
</script>

<style scoped>
.refresh-container {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.refresh-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b6b, #4ecdc4, #45b7d1);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2), 0 0 20px rgba(78, 205, 196, 0.6);
  position: relative;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.5s ease, opacity 0.3s ease;
  perspective: 1000px; /* 增加 3D 效果 */
}

.refresh-button:hover {
  transform: scale(1.15) rotateY(10deg); /* 3D 旋转 */
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3), 0 0 40px rgba(78, 205, 196, 0.8);
  background: linear-gradient(135deg, #ff8e8e, #4ecdc4, #45b7d1);
}

.refresh-button::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.5), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.refresh-button:hover::before {
  opacity: 1;
}

.refresh-button::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3), transparent);
  opacity: 0.9;
  animation: glow 2s ease-in-out infinite;
}

.glow-ring {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  animation: pulseRing 3s ease-in-out infinite;
  z-index: 1;
}

@keyframes pulseRing {
  0% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.2); opacity: 0.6; }
  100% { transform: scale(1); opacity: 0.3; }
}

@keyframes glow {
  0% { opacity: 0.3; }
  50% { opacity: 0.9; }
  100% { opacity: 0.3; }
}

.refresh-icon {
  font-size: 28px;
  color: #ffffff;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 60px; /* 与按钮高度一致，确保垂直居中 */
  vertical-align: middle; /* 确保文字基线居中 */
  text-align: center; /* 确保水平居中 */
  transition: transform 0.3s ease, color 0.3s ease, text-shadow 0.3s ease;
}

.refresh-text, .loading-text {
  margin-left: 15px;
  font-size: 18px;
  font-family: 'Arial', sans-serif;
  color: #333;
  font-weight: bold;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 10px rgba(78, 205, 196, 0.3);
  opacity: 0.9;
  transition: opacity 0.3s ease, color 0.3s ease, text-shadow 0.3s ease;
}

.refresh-text:hover {
  color: #4ecdc4;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 15px rgba(78, 205, 196, 0.5);
}

.loading-text {
  color: #4ecdc4;
  animation: pulse 1.5s ease-in-out infinite, shimmer 2s linear infinite;
}

@keyframes pulse {
  0% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0.7; transform: scale(1); }
}

@keyframes shimmer {
  0% { text-shadow: 0 0 10px rgba(78, 205, 196, 0.3), 0 0 20px rgba(78, 205, 196, 0.5); }
  50% { text-shadow: 0 0 20px rgba(78, 205, 196, 0.5), 0 0 30px rgba(78, 205, 196, 0.7); }
  100% { text-shadow: 0 0 10px rgba(78, 205, 196, 0.3), 0 0 20px rgba(78, 205, 196, 0.5); }
}

.rotating .refresh-icon {
  animation: spin 2s linear infinite, pulseIcon 1.5s ease-in-out infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulseIcon {
  0% { text-shadow: 0 0 5px rgba(255, 255, 255, 0.5), 0 0 10px rgba(255, 255, 255, 0.7); }
  50% { text-shadow: 0 0 10px rgba(255, 255, 255, 0.7), 0 0 15px rgba(255, 255, 255, 0.9); }
  100% { text-shadow: 0 0 5px rgba(255, 255, 255, 0.5), 0 0 10px rgba(255, 255, 255, 0.7); }
}

.particle-effect {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.particle-effect::before,
.particle-effect::after,
.particle-effect::third {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  animation: particle 2s ease-in-out infinite;
}

.particle-effect::before {
  top: 15%;
  left: 15%;
  animation-delay: 0s;
}

.particle-effect::after {
  top: 70%;
  left: 70%;
  animation-delay: 0.8s;
}

.particle-effect::third {
  top: 50%;
  left: 30%;
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.7);
  animation-delay: 1.5s;
}

@keyframes particle {
  0% { transform: translate(0, 0) scale(1); opacity: 0.9; }
  50% { transform: translate(40px, -40px) scale(0.6); opacity: 0.5; }
  100% { transform: translate(0, 0) scale(1); opacity: 0.9; }
}
</style>
